package ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.util.ArrayList;

import javax.swing.JLabel;
import javax.swing.JPanel;

import model.Apartment;
import model.Renter;
import control.CtrApartment;
import control.CtrRenter;
import ui.ItemList;

public class ApartmentPanel extends ItemList{
//	private ArrayList<String> address;
//	private ArrayList<String> email;
//	private ArrayList<String> pPhone;
//	private ArrayList<String> mPhone;
//	private ArrayList<Renter> allRenters;
//	private CtrRenter r;
	private CtrApartment a;
	private ArrayList<Apartment> allAp;
	
	public ApartmentPanel(String name, int sizePctY) {
		super(name, sizePctY);
		//System.out.println("Apartment Constructor Loaded");
		//r = new CtrRenter();
		a = new CtrApartment();
		
		allAp = a.getAllWithRenters();
//		allRenters = r.getAll();
//		allAp = a.getAll();
//			// items
//	//					items = new ArrayList<String>();
//	//					items.add("Nygade 1");
//	//					items.add("Nygade 2");
//	//					items.add("Nygade 3");
//	//					items.add("Nygade 4");
//	//					items.add("Nygade 5");
//	//					items.add("Nygade 6");
//	//					
//						//end items
//		
//		address = new ArrayList<String>();
//		email = new ArrayList<String>();
//		pPhone = new ArrayList<String>();
//		mPhone = new ArrayList<String>();
//
//		for (Renter renter:allRenters){
//			if(!renter.getStatus().equals("WAITING")){
//				address.add(renter.getAddress());
//				email.add(renter.getEmail());
//				mPhone.add(renter.getMobilePhone());
//				pPhone.add(renter.getPrivatePhone());
//	
//			}
//		}
//
//		for (Apartment apart:allAp){
//			if (apart.getStatus().equals("EMPTY")){
//			address.add(apart.getAddress());
//			email.add("N/A");
//			mPhone.add("N/A");
//			pPhone.add("N/A");
//			}
//			
//		}
//	
//		for(int i=0;i<address.size();i++){
//			newPanel(address.get(i),email.get(i),mPhone.get(i),pPhone.get(i));
//		}

		for (Apartment a:allAp){ //added 08-01-2015
			String address = this.setPlaceHolder(a.getAddress());
			String email = this.setPlaceHolder(a.getRent().getRenter().getEmail());
			String mPhone = this.setPlaceHolder(a.getRent().getRenter().getMobilePhone());
			String pPhone = this.setPlaceHolder(a.getRent().getRenter().getPrivatePhone());
			newPanel(address,email,mPhone,pPhone);
//			if (apart.getStatus().equals("EMPTY")){
//				address.add(apart.getAddress());
//				email.add("N/A");
//				mPhone.add("N/A");
//				pPhone.add("N/A");
//			}
		}
	}

	
	private String setPlaceHolder(String s)//added 08-01-2015
	{
		String result = "N/A";
		if(s != null)
		{
			result = s;
		}
		return result;
	}
	@Override
	protected void setPanels(JPanel panel, String item1,String item2, String item3, String item4){
		//System.out.println("Apartment Panels Loaded");
		Font font = new Font("Segoe UI Black", Font.BOLD,20);
		Font font2 = new Font("Segoe UI Black", Font.BOLD,12);
		
		JLabel label1 = new JLabel("A: "+item1);
		label1.setFont(font);
		
		JLabel label2 = new JLabel("<html>Email: "+item2+"<br>MobilePhone: "+item3+"<br>PrivatePhone: "+item4+"</html>");
		label2.setFont(font2);
		

		panel.add(label1,BorderLayout.CENTER);
        panel.add(new ApartmentButtons(Color.RED),BorderLayout.LINE_END);
        panel.add(label2,BorderLayout.PAGE_END);
        
	}
}

